"""
简单的固件下载示例
演示最基本的固件下载流程
"""
from app.controller import DownloadController, MockTransport, g_config


def main():
    """简单的固件下载示例"""
    print("=== 简单固件下载示例 ===")
    
    # 1. 创建下载控制器
    controller = DownloadController(MockTransport())
    
    # 2. 配置CAN参数
    g_config.update_can_config(
        tx_id=0x001,      # 发送CAN ID  
        rx_id=0x001,      # 接收CAN ID
        baudrate=1000000  # 1Mbps
    )
    
    # 3. 初始化系统
    suc, msg = controller.init_system(g_config.can)
    print(f"初始化: {'成功' if suc else '失败'} - {msg}")
    
    if suc:
        # 4. 连接目标设备
        suc, msg = controller.connect_target()
        print(f"连接: {'成功' if suc else '失败'} - {msg}")
        
        # 5. 清理资源
        suc, msg = controller.deinit_system()
        print(f"清理: {'成功' if suc else '失败'} - {msg}")
    
    print("示例完成!")


if __name__ == "__main__":
    main() 